﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Component;


public partial class BackEnd_CartDetailList : System.Web.UI.UserControl
{
    int _IdCart = 0;
    public string _Session = "Chi tiết giỏ hàng";
    protected void Page_Load(object sender, EventArgs e)
    {    
   
        DataBind(CategoryDB.GetAll(true));
        grid.RowCancelingEdit += delegate {  Response.Redirect(Request.Url.ToString()); };
    }
    #region ----------------------------- Ham viet tay -------------------------------------
    void DataBind(object al)
    {
        if (al != null)
        {
            grid.DataKeyNames = new string[] {ColumCategory._Id};
            grid.DataSource = al;
            grid.DataBind();
        }
    }
    #endregion

    protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        object id = grid.DataKeys[e.RowIndex].Value;
        TextBox txtName = (TextBox)grid.Rows[e.RowIndex].FindControl("txtName");
        TextBox txtNameEL = (TextBox)grid.Rows[e.RowIndex].FindControl("txtNameEL");
        TextBox txtPriority = (TextBox)grid.Rows[e.RowIndex].FindControl("txtPriority");
        DropDownList ddlAct = (DropDownList)grid.Rows[e.RowIndex].FindControl("ddlAct");
        Category cat = CategoryDB.GetObjectByid(ConvertType.ToInt(id),true);
        cat.Name = txtName.Text;
        cat.Priority= ConvertType.ToInt(txtPriority.Text.Trim());
        cat.Active = ConvertType.ToBool(ddlAct.Text);
        cat.Save();
         Response.Redirect(Request.Url.ToString());
    }
    protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grid.EditIndex = e.NewEditIndex;
        DataBind(Component.CategoryDB.GetAll(true));
    }
    protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grid.PageIndex = e.NewPageIndex;
        DataBind(Component.CategoryDB.GetAll(true));
    }
}
